package com.ruoyi.project.plus.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.plus.bean.SystemMessage;
import com.ruoyi.project.plus.mapper.SystemMapper;
import com.ruoyi.project.system.domain.User;
import com.ruoyi.project.system.service.IRoomsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/app/Message")
public class MessageController extends BaseController {
    @Autowired
    private SystemMapper systemMapper;

    @ApiOperation("获取消息列表")
    @GetMapping("/list")
    public TableDataInfo list()
    {
        List<SystemMessage> list = systemMapper.selectUserMessage();

        return getDataTable(list);
    }

    @ApiOperation("添加消息")
    @GetMapping("/add")
    public AjaxResult add(String content)
    {
        SystemMessage message = new SystemMessage();
        message.setContent(content);
        message.setCreateTime(new Date());
        message.setUpdateTime(new Date().getTime());
        message.setSenderId(2L);
        message.setReceiveId(3L);
        message.setStatus(0L);
        int num = systemMapper.insert(message);
        if(num < 1){
            return AjaxResult.error("插入失败");
        }
        return AjaxResult.success(message.getMid());
    }


}
